# _*_ coding:utf-8 _*_
# @Time  : 2023.03.17
# @Author: zizlee

import socket  # 导入 socket 模块
import threading

s = socket.socket()  # 创建 socket 对象
s.bind(('127.0.0.1', 12222))  # 绑定端口

s.listen(5)  # 等待客户端连接


def recv_thread(c):
    count = 0
    while True:
        recv_data = c.recv(1024)
        print('收到信息:', recv_data.decode('utf8'))
        count += 1
        if count > 10:
            c.send('close'.encode('utf8'))
            c.close()

while True:
    c, addr = s.accept()  # 建立客户端连接
    print('有客户端连接')
    t = threading.Thread(target=lambda: recv_thread(c), daemon=True)
    t.start()





